package com.example.test1;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;

import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class Main2Activity extends AppCompatActivity {

    @BindView(R.id.mian2_et1)
    EditText mMian2Et1;
    @BindView(R.id.mian2_et2)
    EditText mMian2Et2;
    @BindView(R.id.mian2_bt)
    Button mMian2Bt;
    @BindView(R.id.main2_iv)
    ImageView mMain2Iv;
    @BindView(R.id.fx)
    Button mFx;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        ButterKnife.bind(this);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }

    @OnClick({R.id.mian2_bt, R.id.main2_iv, R.id.fx})
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.mian2_bt:
                if (!mMian2Et1.getText().toString().isEmpty() && !mMian2Et2.getText().toString().isEmpty()) {
                    Intent intent = new Intent(Main2Activity.this, Main3Activity.class);
                    startActivity(intent);
                } else {
                    Toast.makeText(this, "账号或密码不能为空", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.main2_iv:
                UMShareAPI.get(this).getPlatformInfo(this, SHARE_MEDIA.QQ, new UMAuthListener() {
                    @Override
                    public void onStart(SHARE_MEDIA share_media) {

                    }

                    @Override
                    public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) {
                        for (String key : map.keySet()) {
                            Log.e("liangxq", "key=" + key + "value=" + map.get(key));
                        }
                        String name = map.get("name");
                        String expiration = map.get("expiration");
                        mMian2Et1.setText(name);
                        mMian2Et2.setText(expiration);
                    }

                    @Override
                    public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {

                        Log.e("duan", throwable.getMessage());
                    }

                    @Override
                    public void onCancel(SHARE_MEDIA share_media, int i) {

                    }
                });
                break;
            case R.id.fx:
                  UMImage image = new UMImage(Main2Activity.this, R.mipmap.ic_launcher);//网络图片
                                  new ShareAction(Main2Activity.this).withText("hello").withMedia(image).setDisplayList(SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.WEIXIN)
                                          .setCallback(new UMShareListener() {
                                              @Override
                                              public void onStart(SHARE_MEDIA share_media) {

                                              }

                                              @Override
                                              public void onResult(SHARE_MEDIA share_media) {
                                                  Log.e("liangxq", "onResult");
                                              }

                                              @Override
                                              public void onError(SHARE_MEDIA share_media, Throwable throwable) {
                                                  Log.e("liangxq", throwable.getMessage());
                                              }

                                              @Override
                                              public void onCancel(SHARE_MEDIA share_media) {

                                              }
                                          }).open();
                break;
        }
    }
}
